<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    var minimumSize = function (nums, maxOperations) {
      let left = 0;
      let right = 1e9;
      let op = 0;
      while (left < right) {
        let mid = left + Math.floor((right - left) / 2);
        for (let i = 0; i < nums.length; i++) {
          if (mid < nums[i]) {
            op += Math.ceil(nums[i] / mid) - 1;
          }
        }
        if (op <= maxOperations) {
          right = mid;
        } else {
          left = mid + 1;
        }
      }
      return left;

    }
    console.log(minimumSize([2, 4, 8, 2], 4));
  </script>
</body>

</html>